if(WScript.FullName.toLowerCase().indexOf("wscript") >= 0)
{
	WScript.echo("Please use cscript.exe scripting host to run this script.");
	WScript.quit();
}

Enumerator.prototype.toArray = function()
{
	var array = [];
	for(; !this.atEnd(); this.moveNext())
		array.push(this.item());
	return array;
}


var oshHost = GetObject("", "OSH.Host");

var progDvb = oshHost.GetService("Osh.ProgDvb.ProgDvbApplication");
var db = progDvb.ChannelDatabase;

db.Reload();

WScript.echo(db.Path);

var channels = new Enumerator(db.Channels).toArray();
for(c in channels)
{
	var channel = channels[c];
	WScript.echo("        " + channel.IdString + " " + channel.ChannelNumber + " " + channel.Name);
}	

var channelTrees = new Enumerator(db.ChannelTrees).toArray();
for(i in channelTrees)
{
	var channelTree = channelTrees[i];

	WScript.echo(channelTree.Path);
	WScript.echo(channelTree.Name);
	
	var channelTreeFolders = new Enumerator(channelTree.Folders).toArray();
	for(f in channelTreeFolders)
	{
		var folder = channelTreeFolders[f];
		WScript.echo("    " + folder.Name);

		var channels = new Enumerator(folder.Channels).toArray();
		for(c in channels)
		{
			var channel = channels[c];
			WScript.echo("        " + channel.IdString + " " + channel.ChannelNumber + " " + channel.Name);
		}	
	}

}



